package com.aim.util.filters;


import java.util.Collection;
import java.util.HashSet;

/**
 * User: Avraham Shvartzon
 * Date: 6/17/14
 */
public class InCollectionFilter<T> implements Filter<T>{

    private Collection<T> collection;

    private boolean containMask;

    public InCollectionFilter(){
        this(true);
    }

    public InCollectionFilter(boolean containMask){
        this(new HashSet<T>(), containMask);
    }

    public void add(T t){
        collection.add(t);
    }

    public InCollectionFilter(Collection<T> collection, boolean containMask){
        this.containMask = containMask;
        this.collection = collection;
    }

    @Override
    public boolean accept(T t) {
        return containMask == collection.contains(t);
    }
}
